import os
from dotenv import load_dotenv

basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(os.path.dirname(basedir), '.env'))

class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard-to-guess-string'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    MAX_CONTENT_LENGTH = 500 * 1024 * 1024  # 500MB

    # 七牛云配置
    QINIU_ACCESS_KEY = os.environ.get('QINIU_ACCESS_KEY')
    QINIU_SECRET_KEY = os.environ.get('QINIU_SECRET_KEY')
    QINIU_BUCKET_NAME = os.environ.get('QINIU_BUCKET_NAME')
    QINIU_DOMAIN = os.environ.get('QINIU_DOMAIN')
    QINIU_REGION = os.environ.get('QINIU_REGION')

    # 确保数据库配置正确
    SQLALCHEMY_DATABASE_URI = 'sqlite:////www/wwwroot/spvi.lingbankeji.com/instance/videos.db'

    @staticmethod
    def init_app(app):
        db_path = '/www/wwwroot/spvi.lingbankeji.com/instance'
        if not os.path.exists(db_path):
            os.makedirs(db_path)

class DevelopmentConfig(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')

class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
        'sqlite://'

class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data.sqlite')

config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}